# coding=utf-8
from datetime import datetime

from flask import Flask, jsonify, request

from config import logger


def init_app(application):
    @application.route('/')
    def index():
        return jsonify(
            datetime=datetime.now().strftime('%y-%m-%d %H:%M:%S'),
            msg='Welcome to you cute api!'
        )

    @application.route('/health', methods=['GET'])
    def check_health():
        return jsonify(status='ok')

    @application.before_request
    def before_request():
        logger.info('request: {}'.format(request.data))

    @application.after_request
    def after_request(response):
        logger.info('response: {}'.format(response.data))
        return response

    from handles.handleBearyChat import bearyRouter
    from handles.handleWx import wxRouter
    application.register_blueprint(bearyRouter)
    application.register_blueprint(wxRouter)


def get_app():
    application = Flask(__name__)
    init_app(application)
    return application


app = get_app()

if __name__ == '__main__':
    app.run(debug=True, port=9999)
